<template>
  <div>
    <div>
      <div class="policy-title-text">政策信息</div>
      <el-row :gutter="20">
        <el-form
          :model="policyForm"
          :rules="policyRules"
          ref="policyForm"
          label-width="120px"
        >
          <el-col :span="6">
            <el-form-item label="政策名称:" prop="polName">
              <el-input
                size="small"
                v-model="policyForm.polName"
                placeholder="请输入政策名称"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="政策类型:" prop="polType">
              <el-select
                size="small"
                v-model="policyForm.polType"
                placeholder="请选择政策类型"
              >
                <el-option
                  :label="item.dictValue"
                  :value="item.dictKey"
                  v-for="(item, index) in polTypeList"
                  :key="index"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="政策类别:" prop="polCategory">
              <el-select
                size="small"
                v-model="policyForm.polCategory"
                placeholder="请选择政策类别"
              >
                <el-option
                  :label="item.dictValue"
                  :value="item.dictKey"
                  v-for="(item, index) in polCategoryList"
                  :key="index"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="政策分类:" prop="polKind">
              <el-select
                size="small"
                v-model="policyForm.polKind"
                placeholder="请选择政策分类"
              >
                <el-option
                  :label="item.dictValue"
                  :value="item.dictKey"
                  v-for="(item, index) in polKindList"
                  :key="index"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
    </div>
    <div>
      <div class="policy-title-text">分润配置</div>
    </div>
    <div
      class="
        w100
        haruyuki-flex-space-between
        haruyuki-align-items-center
        haruyuki-mb-20
      "
    >
      <div class="haruyuki-flex-center">
        <span class="haruyuki-size-14">选择通道：</span>
        <el-select
          size="mini"
          v-model="aisleData"
          @change="templateAllChange"
          placeholder="请选择通道"
        >
          <el-option
            v-for="item in aisleList"
            :key="item.aisleCode"
            :label="item.aisleName"
            :value="item.aisleCode"
          >
          </el-option>
        </el-select>
      </div>
      <div class="haruyuki-flex-center">
        <div class="haruyuki-mr-10">
          <span>成本费率(比例)：</span>
          <el-input-number
            size="mini"
            v-model="aptTemplate.aptRate"
            :precision="4"
            :step="0.0001"
            :min="0"
            :max="1"
          ></el-input-number>
          <span> %</span>
        </div>
        <div class="haruyuki-mr-10">
          <span>分润(比例)：</span>
          <el-input-number
            size="mini"
            v-model="aptTemplate.aptScale"
            :precision="0"
            :min="1"
            :max="100"
          ></el-input-number>
          <span> %</span>
        </div>
        <div class="haruyuki-mr-10">
          <span>封顶金额(笔)：</span>
          <el-input-number
            size="mini"
            v-model="aptTemplate.aptMax"
            :precision="2"
            :step="0.1"
            :min="0"
          ></el-input-number>
          <span> ¥</span>
        </div>
        <div class="haruyuki-mr-10">
          <span>封底金额(笔)：</span>
          <el-input-number
            size="mini"
            v-model="aptTemplate.aptMin"
            :precision="2"
            :step="0.1"
            :min="0"
          ></el-input-number>
          <span> ¥</span>
        </div>
        <el-button type="primary" size="small" plain @click="submitCover"
          >一键填入</el-button
        >
      </div>
    </div>
    <!-- 政策模板 START -->
    <div class="haruyuki-scrollbar-70vh haruyuki-p-10">
      <div class="tree aisle-policy-bg" v-for="(dataItem, dataIndex) in data" :key="dataIndex">
        <details open>
          <summary class="summary-box">
            <div
              class="tree-item w100 haruyuki-flex-space-between haruyuki-align-items-center"
            >
              <div class="haruyuki-flex1">
                <span class="haruyuki-size-16 policy-ml-3 policy-mr-3"
                  >通道名称：{{ dataItem.aisleName }}</span
                >
              </div>
              <div class="haruyuki-flex-center">
                <div class="haruyuki-mr-10">
                  <span>成本费率(比例)：</span>
                  <el-input-number
                    size="mini"
                    v-model="dataItem.aptRate"
                    :precision="4"
                    :step="0.0001"
                    :min="0"
                    :max="1"
                  ></el-input-number>
                  <span> %</span>
                </div>
                <div class="haruyuki-mr-10">
                  <span>分润(比例)：</span>
                  <el-input-number
                    size="mini"
                    v-model="dataItem.aptScale"
                    :precision="0"
                    :min="1"
                    :max="100"
                  ></el-input-number>
                  <span> %</span>
                </div>
                <div class="haruyuki-mr-10">
                  <span>封顶金额(笔)：</span>
                  <el-input-number
                    size="mini"
                    v-model="dataItem.aptMax"
                    :precision="2"
                    :step="0.1"
                    :min="0"
                  ></el-input-number>
                  <span> ¥</span>
                </div>
                <div class="haruyuki-mr-10">
                  <span>封底金额(笔)：</span>
                  <el-input-number
                    size="mini"
                    v-model="dataItem.aptMin"
                    :precision="2"
                    :step="0.1"
                    :min="0"
                  ></el-input-number>
                  <span> ¥</span>
                </div>
                <div class="policy-mr-3">
                  <el-button
                    type="primary"
                    size="mini"
                    plain
                    @click.stop="submitChildCover(dataItem)"
                    >一键填入</el-button
                  >
                </div>
                <div class="policy-mr-3">
                  <el-button
                    type="danger"
                    size="mini"
                    plain
                    @click.stop="policyDelete(index)"
                    >删除通道</el-button
                  >
                </div>
              </div>
            </div>
          </summary>
          <details v-for="(item, index) in dataItem.levelList" :key="index" open>
            <summary class="haruyuki-flex haruyuki-align-items-center">
              <div class="tree-item haruyuki-flex-center">
                <span class="haruyuki-mr-20">阶梯{{ index + 1 }}</span>
                <div class="haruyuki-flex haruyuki-align-items-center">
                  范围区间：<el-input-number
                    size="mini"
                    v-model="item.aptStartMoney"
                    :precision="2"
                    :step="0.1"
                    :min="0"
                  ></el-input-number
                  ><span>~</span
                  ><el-input-number
                    size="mini"
                    v-model="item.aptEndMoney"
                    :precision="2"
                    :step="0.1"
                    :min="0.1"
                  ></el-input-number>
                  <div
                    class="policy-ml-3 policy-mr-3"
                    v-if="item.id == dataItem.stateIndex"
                  >
                    <el-button
                      type="text"
                      size="mini"
                      @click="() => ladderAppend(item, index, dataIndex)"
                    >
                      新增
                    </el-button>
                  </div>
                  <div
                    class="policy-ml-3"
                    v-if="item.id == dataItem.stateIndex && index != 0"
                  >
                    <el-button
                      type="text"
                      size="mini"
                      @click="() => ladderRemove(index, dataIndex)"
                    >
                      删除
                    </el-button>
                  </div>
                </div>
              </div>
            </summary>
            <!-- 扫码 START -->
            <details open>
              <summary>
                <span class="tree-item">{{ item.typeVO.scanRate.typeName }}</span>
              </summary>
              <details v-for="(cItem, cIndex) in item.typeVO.scanRate.rateList" :key="cIndex" open>
                <summary>
                  <span class="tree-item">{{ cItem.compName }}</span>
                </summary>
                <div v-if="cItem.payType == 3">
                  <details open>
                    <summary>
                      <span class="tree-item">银联二维码小额（小于等于1000）</span>
                    </summary>
                    <details v-for="(uItem, uIndex) in ysfRateList(cItem.unionRate, 1)" :key="uIndex" open>
                      <summary>
                        <!-- <span class="tree-item">{{ cItem.compName }}{{ ysfRateTypeName(uItem.ylType) }}</span> -->
                        <span class="tree-item">银联小额{{ ysfRateTypeName(uItem.ylType) }}</span>
                      </summary>
                      <details>
                        <summary>
                          <div class="tree-item input-tree-item">
                            <!-- <span class="input-tree-item-left">{{ cItem.compName }}成本费率(比例)：</span> -->
                            <span class="input-tree-item-left">银联小额成本费率(比例)：</span>
                            <el-input
                              class="haruyuki-width-100"
                              size="mini"
                              v-model="uItem.rate"
                              onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                              @keyup.native="proving($event)"
                            ></el-input>
                            <span class="p_L10">%</span>
                          </div>
                          <div class="tree-item input-tree-item">
                            <!-- <span class="input-tree-item-left">{{ cItem.compName }}分润(比例)：</span> -->
                            <span class="input-tree-item-left">银联小额分润(比例)：</span>
                            <el-input
                              class="haruyuki-width-100"
                              size="mini"
                              v-model="uItem.scale"
                              onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                              @keyup.native="proving($event)"
                            ></el-input>
                            <span class="p_L10">%</span>
                          </div>
                          <div class="tree-item input-tree-item" v-if="uItem.ylType == 2 || uItem.ylType == 4">
                            <!-- <span class="input-tree-item-left">{{ cItem.compName }}封顶金额(笔)：</span> -->
                            <span class="input-tree-item-left">银联小额封顶金额(笔)：</span>
                            <el-input
                              class="haruyuki-width-100"
                              size="mini"
                              v-model="uItem.aptMax"
                              onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                              @keyup.native="proving($event)"
                            ></el-input>
                            <span class="p_L10">元</span>
                          </div>
                          <div class="tree-item input-tree-item">
                            <!-- <span class="input-tree-item-left">{{ cItem.compName }}封底金额(笔)：</span> -->
                            <span class="input-tree-item-left">银联小额封底金额(笔)：</span>
                            <el-input
                              class="haruyuki-width-100"
                              size="mini"
                              v-model="uItem.aptMin"
                              onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                              @keyup.native="proving($event)"
                            ></el-input>
                            <span class="p_L10">元</span>
                          </div>
                        </summary>
                      </details>
                    </details>
                  </details>
                  <details open>
                    <summary>
                      <span class="tree-item">银联二维码大额（大于等于1000）</span>
                    </summary>
                    <details v-for="(uItem, uIndex) in ysfRateList(cItem.unionRate, 2)" :key="uIndex" open>
                      <summary>
                        <!-- <span class="tree-item">{{ cItem.compName }}{{ ysfRateTypeName(uItem.ylType) }}</span> -->
                        <span class="tree-item">银联大额{{ ysfRateTypeName(uItem.ylType) }}</span>
                      </summary>
                      <details>
                        <summary>
                          <div class="tree-item input-tree-item">
                            <!-- <span class="input-tree-item-left">{{ cItem.compName }}成本费率(比例)：</span> -->
                            <span class="input-tree-item-left">银联大额成本费率(比例)：</span>
                            <el-input
                              class="haruyuki-width-100"
                              size="mini"
                              v-model="uItem.rate"
                              onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                              @keyup.native="proving($event)"
                            ></el-input>
                            <span class="p_L10">%</span>
                          </div>
                          <div class="tree-item input-tree-item">
                            <!-- <span class="input-tree-item-left">{{ cItem.compName }}分润(比例)：</span> -->
                            <span class="input-tree-item-left">银联大额分润(比例)：</span>
                            <el-input
                              class="haruyuki-width-100"
                              size="mini"
                              v-model="uItem.scale"
                              onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                              @keyup.native="proving($event)"
                            ></el-input>
                            <span class="p_L10">%</span>
                          </div>
                          <div class="tree-item input-tree-item" v-if="uItem.ylType == 2 || uItem.ylType == 4">
                            <!-- <span class="input-tree-item-left">{{ cItem.compName }}封顶金额(笔)：</span> -->
                            <span class="input-tree-item-left">银联大额封顶金额(笔)：</span>
                            <el-input
                              class="haruyuki-width-100"
                              size="mini"
                              v-model="uItem.aptMax"
                              onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                              @keyup.native="proving($event)"
                            ></el-input>
                            <span class="p_L10">元</span>
                          </div>
                          <div class="tree-item input-tree-item">
                            <!-- <span class="input-tree-item-left">{{ cItem.compName }}封底金额(笔)：</span> -->
                            <span class="input-tree-item-left">银联大额封底金额(笔)：</span>
                            <el-input
                              class="haruyuki-width-100"
                              size="mini"
                              v-model="uItem.aptMin"
                              onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                              @keyup.native="proving($event)"
                            ></el-input>
                            <span class="p_L10">元</span>
                          </div>
                        </summary>
                      </details>
                    </details>
                  </details>
                </div>
                <div v-else>
                  <details open>
                    <summary>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">{{ cItem.compName }}成本费率(比例)：</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.rate"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                        <span class="p_L10">%</span>
                      </div>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">{{ cItem.compName }}分润(比例)：</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.scale"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                        <span class="p_L10">%</span>
                      </div>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">{{ cItem.compName }}封顶金额(笔)：</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.aptMax"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                        <span class="p_L10">元</span>
                      </div>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">{{ cItem.compName }}封底金额(笔)：</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.aptMin"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                        <span class="p_L10">元</span>
                      </div>
                    </summary>
                  </details>
                </div>
              </details>
            </details>
            <!-- 扫码 END -->
            <!-- 刷卡 START -->
            <details open>
              <summary>
                <span class="tree-item">{{ item.typeVO.posRate.typeName }}</span>
              </summary>
              <details v-for="(cItem, cIndex) in item.typeVO.posRate.rateList" :key="cIndex" open>
                <summary>
                  <span class="tree-item">{{ posRateTypeName(cItem.payType) }}</span>
                </summary>
                <!-- payType  刷卡 1.贷记卡 2.借记卡 -->
                <details>
                  <summary>
                    <template v-if="cItem.payType == 1">
                      <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">贷记卡刷卡成本费率(比例)：</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.rate"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                      <span class="p_L10">%</span>
                    </div>
                    <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">贷记卡刷卡分润(比例)：</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.scale"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                      <span class="p_L10">%</span>
                    </div>
                    <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">贷记卡刷卡封底金额(笔)：</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.aptMin"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                      <span class="p_L10">元</span>
                    </div>
                    </template>

                    <template v-if="cItem.payType == 2">
                      <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">借记卡刷卡成本费率(比例)：</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.rate"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                      <span class="p_L10">%</span>
                    </div>
                    <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">借记卡刷卡分润(比例)：</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.scale"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                      <span class="p_L10">%</span>
                    </div>
                    <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">借记卡刷卡封顶金额(笔)：</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.aptMax"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                      <span class="p_L10">元</span>
                    </div>
                    <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">借记卡刷卡封底金额(笔)：</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.aptMin"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                      <span class="p_L10">元</span>
                    </div>
                  </template>
                    
                  </summary>
                </details>
              </details>
            </details>
            <!-- 刷卡 END -->
            <!-- 云闪付 START -->
            <details open>
              <summary>
                <span class="tree-item">{{ item.typeVO.ysfRate.typeName }}</span>
              </summary>
              <details open>
                <summary>
                  <span class="tree-item">云闪付优惠（小于等于1000）</span>
                </summary>
                <details v-for="(cItem, cIndex) in ysfRateList(item.typeVO.ysfRate.rateList, 1)" :key="cIndex" open>
                  <summary>
                    <span class="tree-item">云闪付优惠{{ ysfRateTypeName(cItem.ylType) }}</span>
                  </summary>
                  <details>
                    <summary>
                      <div class="tree-item input-tree-item">
                        <!-- <span class="input-tree-item-left">{{ cItem.compName }}成本费率(比例)：</span> -->
                        <span class="input-tree-item-left">云闪付优惠成本费率(比例)：</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.rate"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                        <span class="p_L10">%</span>
                      </div>
                      <div class="tree-item input-tree-item">
                        <!-- <span class="input-tree-item-left">{{ cItem.compName }}分润(比例)：</span> -->
                        <span class="input-tree-item-left">云闪付优惠分润(比例)：</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.scale"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                        <span class="p_L10">%</span>
                      </div>
                      <div class="tree-item input-tree-item" v-if="cItem.ylType == 2 || cItem.ylType == 4">
                        <span class="input-tree-item-left">云闪付优惠封顶金额(笔)：</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.aptMax"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                        <span class="p_L10">元</span>
                      </div>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">云闪付优惠封底金额(笔)：</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.aptMin"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                        <span class="p_L10">元</span>
                      </div>
                    </summary>
                  </details>
                </details>
              </details>
              <details open>
                <summary>
                  <span class="tree-item">云闪付（大于等于1000）</span>
                </summary>
                <details v-for="(cItem, cIndex) in ysfRateList(item.typeVO.ysfRate.rateList, 2)" :key="cIndex" open>
                  <summary>
                    <span class="tree-item">云闪付{{ ysfRateTypeName(cItem.ylType) }}</span>
                  </summary>
                  <details>
                    <summary>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">云闪付成本费率(比例)：</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.rate"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                        <span class="p_L10">%</span>
                      </div>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">云闪付分润(比例)：</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.scale"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                        <span class="p_L10">%</span>
                      </div>
                      <div class="tree-item input-tree-item" v-if="cItem.ylType == 2 || cItem.ylType == 4">
                        <span class="input-tree-item-left">云闪付封顶金额(笔)：</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.aptMax"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                        <span class="p_L10">元</span>
                      </div>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">云闪付封底金额(笔)：</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.aptMin"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                        <span class="p_L10">元</span>
                      </div>
                    </summary>
                  </details>
                </details>
              </details>
            </details>
            <!-- 云闪付 END -->
            <!-- 快捷 START -->
            <details open>
              <summary>
                <span class="tree-item">{{ item.typeVO.quickRate.typeName }}</span>
              </summary>
              <details v-for="(cItem, cIndex) in item.typeVO.quickRate.rateList" :key="cIndex" open>
                <summary>
                  <span class="tree-item">快捷支付</span>
                </summary>
                <details>
                  <summary>
                    <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">快捷成本费率(比例)：</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.rate"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                      <span class="p_L10">%</span>
                    </div>
                    <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">快捷分润(比例)：</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.scale"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                      <span class="p_L10">%</span>
                    </div>
                  </summary>
                </details>
              </details>
            </details>
            <!-- 快捷 END -->
            <!-- 垫资 START -->
            <details open>
              <summary>
                <span class="tree-item">{{ item.typeVO.codeAdvanceRate.typeName }}</span>
              </summary>
              <details v-for="(cItem, cIndex) in item.typeVO.codeAdvanceRate.rateList" :key="cIndex" open>
                <summary>
                  <span class="tree-item">{{ codeAdvanceRateTypeName(cItem.ylType) }}</span>
                </summary>
                <details>
                  <summary>
                    <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">{{ codeAdvanceRateTypeName(cItem.ylType) }}成本费率(比例)：</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.rate"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                      <span class="p_L10">%</span>
                    </div>
                    <div class="tree-item input-tree-item" v-if="cItem.ylType == 2 || cItem.ylType == 3">
                      <span class="input-tree-item-left">{{ codeAdvanceRateTypeName(cItem.ylType) }}封顶金额(笔)：</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.aptMax"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                      <span class="p_L10">元</span>
                    </div>
                    <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">{{ codeAdvanceRateTypeName(cItem.ylType) }}封底金额(笔)：</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.aptMin"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                      <span class="p_L10">元</span>
                    </div>
                  </summary>
                </details>
              </details>
            </details>
            <!-- 垫资 END -->
          </details>
        </details>
      </div>
    </div>
    <!-- 政策模板 END -->
  </div>
</template>

<script>
import { getDictionary } from "@/api/system/dict";
import {
  getAisleList,
  getAisleDetail,
} from "@/api/rb-core/oempolicy/oem_policy";
let intId = 1;
let pid = 1000;
export default {
  props: {
    policyForm: Object,
    oem: Object,
  },
  data() {
    return {
      policyRules: {
        polName: [
          { required: true, message: "请输入政策名称", trigger: "blur" },
        ],
        polType: [
          { required: true, message: "请选择政策类型", trigger: "blur" },
        ],
        polCategory: [
          { required: true, message: "请选择政策类别", trigger: "blur" },
        ],
        polKind: [
          { required: true, message: "请选择政策分类", trigger: "blur" },
        ],
      },
      polTypeList: [],
      polCategoryList: [],
      polKindList: [],
      initData: [],
      data: [], //通道政策 树形数据
      aisleList: [],
      aisleData: null,
      aptTemplate: {
        aptRate: 0,
        aptScale: 0,
        aptMax: 0,
        aptMin: 0,
      },
    };
  },
  computed: {
    /* 垫资 ylType 1.扫码垫资 2.贷记卡垫资 3.借记卡垫资 */
    codeAdvanceRateTypeName() {
      return (val) => {
        if (val == 1) {
          return (val = '扫码垫资');
        } else if (val == 2) {
          return (val = '贷记卡垫资');
        } else if (val == 3) {
          return (val = '借记卡垫资');
        }
      };
    },
    /* 刷卡 payType 1.贷记卡 2.借记卡 */
    posRateTypeName() {
      return (val) => {
        if (val == 1) {
          return (val = '贷记卡');
        } else if (val == 2) {
          return (val = '借记卡');
        }
      };
    },
    /* 云闪付 ylType 1.贷记卡小额 2.借记卡小额 3.贷记卡大额 4.借记卡大额 */
    ysfRateTypeName() {
      return (val) => {
        if (val == 1) {
          return (val = '贷记卡小额');
        } else if (val == 2) {
          return (val = '借记卡小额');
        } else if (val == 3) {
          return (val = '贷记卡大额');
        } else if (val == 4) {
          return (val = '借记卡大额');
        }
      };
    },
    /* 云闪付 大小额分层 */
    ysfRateList() {
      return (unionRate, type) => {
        if (type == 1) {
          return unionRate.filter(item => item.ylType == 1 || item.ylType == 2)
        } else if (type == 2) {
          return unionRate.filter(item => item.ylType == 3 || item.ylType == 4)
        }
      };
    }
  },
  watch: {
    data: {
      deep: true,
      handler(val) {
        if (val) {
          for (let i = 0; i < val.length; i++) {
            val[i].stateIndex = val[i].levelList[val[i].levelList.length - 1].id;
          }
        }
      },
    },
  },
  created() {
    this.data = [];
    this.doGetDicts();
    this.getAisleSelect();
  },
  methods: {
    /* 字典 */
    doGetDicts() {
      getDictionary({ code: "pol_type" }).then((res) => {
        this.polTypeList = res.data.data;
      });
      getDictionary({ code: "pol_category" }).then((res) => {
        this.polCategoryList = res.data.data;
      });
      getDictionary({ code: "pol_kind" }).then((res) => {
        this.polKindList = res.data.data;
      });
    },
    /* 通道列表 */
    getAisleSelect() {
      getAisleList("-1", "-1").then((res) => {
        this.aisleList = res.data.data.records;
      });
    },
    /* 选中通道 渲染政策模板 */
    templateAllChange(e) {
      this.$confirm("是否为该通道新增模板?", "新增模板", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      })
        .then(() => {
          if (this.data.length > 0) {
            for (const item of this.data) {
              if (e === item.aisleCode) {
                this.$message({
                  type: "warning",
                  message: "无法重复新增此通道为模板！",
                });
                return false;
              }
            }
          }

          getAisleDetail(e).then((res) => {
            if (res.data.code == "200") {
              this.initData.push(res.data.data);
              for (let i = 0; i < this.initData.length; i++) {
                this.$set(this.initData[i], "aptRate", 0);
                this.$set(this.initData[i], "aptScale", 0);
                this.$set(this.initData[i], "aptMax", 0);
                this.$set(this.initData[i], "aptMin", 0);
                this.$set(this.initData[i], "stateIndex", 0);
                for (let j = 0; j < this.initData[i].levelList.length; j++) {
                  this.$set(this.initData[i].levelList[j], "id", intId++);
                }
              }
              this.$nextTick(() => {
                this.data = JSON.parse(JSON.stringify(this.initData));
              });
              this.$message({
                type: "success",
                message: "新增成功!",
              });
            } else {
              this.$message({
                type: "error",
                message: res.data.message,
              });
            }
          });
        })
        .catch(() => {
          this.aisleData = null;
          // this.$message({
          //   type: "info",
          //   message: "已取消",
          // });
        });
    },
    getEditDatail(data) {
      this.initData = data.policyList;
      for (let i = 0; i < this.initData.length; i++) {
        this.$set(this.initData[i], "aptRate", 0);
        this.$set(this.initData[i], "aptScale", 0);
        this.$set(this.initData[i], "aptMax", 0);
        this.$set(this.initData[i], "aptMin", 0);
        this.$set(this.initData[i], "stateIndex", 0);
        for (let j = 0; j < this.initData[i].levelList.length; j++) {
          this.$set(this.initData[i].levelList[j], "id", intId++);
        }
      }
      this.$nextTick(() => {
        this.data = JSON.parse(JSON.stringify(this.initData));
      });
    },
    /* 删除对应的通道政策 */
    policyDelete(i) {
      this.$confirm("是否删除该通道政策模板?", "删除", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      })
        .then(() => {
          this.data.splice(i, 1);
          this.initData.splice(i, 1);
          this.aisleData = null;
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          // this.$message({
          //   type: "info",
          //   message: "已取消",
          // });
        });
    },
    /* 全通道政策模板 一键填入 */
    submitCover() {
      if (this.aptTemplate.aptRate == 0) {
        this.$message({
          type: "warning",
          message: "请输入成本费率(比例)",
        });
      } else if (this.aptTemplate.aptScale == 0) {
        this.$message({
          type: "warning",
          message: "请输入结算比例",
        });
      } else if (this.aptTemplate.aptMax == 0) {
        this.$message({
          type: "warning",
          message: "请输入封顶金额(笔)",
        });
      } else if (this.aptTemplate.aptMin == 0) {
        this.$message({
          type: "warning",
          message: "请输入最低金额(笔)",
        });
      } else {
        for (let d = 0; d < this.data.length; d++) {
          for (let i = 0; i < this.data[d].levelList.length; i++) {
            for (const codeAdvanceRate of this.data[d].levelList[i].typeVO.codeAdvanceRate.rateList) {
              codeAdvanceRate.rate = this.aptTemplate.aptRate;
              codeAdvanceRate.scale = this.aptTemplate.aptScale;
              codeAdvanceRate.aptMax = this.aptTemplate.aptMax;
              codeAdvanceRate.aptMin = this.aptTemplate.aptMin;
            }

            for (const posRate of this.data[d].levelList[i].typeVO.posRate.rateList) {
              posRate.rate = this.aptTemplate.aptRate;
              posRate.scale = this.aptTemplate.aptScale;
              posRate.aptMax = this.aptTemplate.aptMax;
              posRate.aptMin = this.aptTemplate.aptMin;
            }

            for (const quickRate of this.data[d].levelList[i].typeVO.quickRate.rateList) {
              quickRate.rate = this.aptTemplate.aptRate;
              quickRate.scale = this.aptTemplate.aptScale;
              quickRate.aptMax = this.aptTemplate.aptMax;
              quickRate.aptMin = this.aptTemplate.aptMin;
            }

            for (const scanRate of this.data[d].levelList[i].typeVO.scanRate.rateList) {
              if (scanRate.payType == 3) {
                for (const scanRateItem of scanRate.unionRate) {
                  scanRateItem.rate = this.aptTemplate.aptRate;
                  scanRateItem.scale = this.aptTemplate.aptScale;
                  scanRateItem.aptMax = this.aptTemplate.aptMax;
                  scanRateItem.aptMin = this.aptTemplate.aptMin;
                }
              } else {
                scanRate.rate = this.aptTemplate.aptRate;
                scanRate.scale = this.aptTemplate.aptScale;
                scanRate.aptMax = this.aptTemplate.aptMax;
                scanRate.aptMin = this.aptTemplate.aptMin;
              }
            }

            for (const ysfRate of this.data[d].levelList[i].typeVO.ysfRate.rateList) {
              ysfRate.rate = this.aptTemplate.aptRate;
              ysfRate.scale = this.aptTemplate.aptScale;
              ysfRate.aptMax = this.aptTemplate.aptMax;
              ysfRate.aptMin = this.aptTemplate.aptMin;
            }
          }
        }
        
      }
    },
    /* 单通道政策模板 一键填入 */
    submitChildCover(data) {
      if (data.aptRate == 0) {
        this.$message({
          type: "warning",
          message: "请输入成本费率(比例)",
        });
      } else if (data.aptScale == 0) {
        this.$message({
          type: "warning",
          message: "请输入分润比例",
        });
      } else if (data.aptMax == 0) {
        this.$message({
          type: "warning",
          message: "请输入封顶金额(笔)",
        });
      } else if (data.aptMin == 0) {
        this.$message({
          type: "warning",
          message: "请输入封低金额(笔)",
        });
      } else {
        for (let i = 0; i < data.levelList.length; i++) {
          for (const codeAdvanceRate of data.levelList[i].typeVO.codeAdvanceRate.rateList) {
            codeAdvanceRate.rate = data.aptRate;
            codeAdvanceRate.scale = data.aptScale;
            codeAdvanceRate.aptMax = data.aptMax;
            codeAdvanceRate.aptMin = data.aptMin;
          }

          for (const posRate of data.levelList[i].typeVO.posRate.rateList) {
            posRate.rate = data.aptRate;
            posRate.scale = data.aptScale;
            posRate.aptMax = data.aptMax;
            posRate.aptMin = data.aptMin;
          }

          for (const quickRate of data.levelList[i].typeVO.quickRate.rateList) {
            quickRate.rate = data.aptRate;
            quickRate.scale = data.aptScale;
            quickRate.aptMax = data.aptMax;
            quickRate.aptMin = data.aptMin;
          }

          for (const scanRate of data.levelList[i].typeVO.scanRate.rateList) {
            if (scanRate.payType == 3) {
              for (const scanRateItem of scanRate.unionRate) {
                scanRateItem.rate = data.aptRate;
                scanRateItem.scale = data.aptScale;
                scanRateItem.aptMax = data.aptMax;
                scanRateItem.aptMin = data.aptMin;
              }
            } else {
              scanRate.rate = data.aptRate;
              scanRate.scale = data.aptScale;
              scanRate.aptMax = data.aptMax;
              scanRate.aptMin = data.aptMin;
            }
          }

          for (const ysfRate of data.levelList[i].typeVO.ysfRate.rateList) {
            ysfRate.rate = data.aptRate;
            ysfRate.scale = data.aptScale;
            ysfRate.aptMax = data.aptMax;
            ysfRate.aptMin = data.aptMin;
          }
        }
      }
    },
    /* 新增阶梯 */
    ladderAppend(data, index, dataIndex) {
      let intData = JSON.parse(JSON.stringify(data));
      intData.id = intId++;
      intData.aptStartMoney = intData.aptEndMoney;
      intData.aptEndMoney = intData.aptEndMoney + 1;
      intData.aptGrade = intData.id; //阶段层级赋值

      this.initData[dataIndex].levelList.push(intData);
      this.data[dataIndex].levelList.push(intData);
    },
    /* 删除阶梯 */
    ladderRemove(index, dataIndex) {
      this.initData[dataIndex].levelList.splice(index, 1);
      this.data[dataIndex].levelList.splice(index, 1);
    },
    /* input 数值检验 */
    proving(e) {
      var keynum = window.event ? e.keyCode : e.which;   //获取键盘码
      // var keychar = String.fromCharCode(keynum);  //获取键盘码对应的字符
      if (keynum == 189 || keynum == 109) { //禁止输入负数
        e.target.value = 0
      }
      // if (e.target.value.indexOf('.') == 1) { //如果值里面有’.‘的话，进去检测位小数点大于1位的话只保留一位
      //     var x = String(e.target.value).indexOf(".")+4;//得到小数点的位置
      //     var y = String(e.target.value).length - x;//小数点的位数
      //     if(y > 1){
      //         e.target.value = this.getBit(e.target.value, 4)
      //     }
      // }
      if (e.target.value.indexOf(".") != -1) {
        e.target.value = e.target.value.replace(/\.{2,}/g, '.')
        if (e.target.value.length > 6) {
          e.target.value = e.target.value.substr(0, e.target.value.length - 1)
        }
      }
      // if (e.target.value > 1) {
      //     e.target.value = 1
      // }
    },
  },
};
</script>

<style lang="scss" scoped>
.haruyuki-width-100{
  // width: 300px !important;
  width:inherit;
}
.w100{
  width: 100%;
}
.p_L10{
  padding-left: 4px !important;
}
.policy-title-text {
  font-size: 22px;
  margin-bottom: 14px;
}
details {
  padding-left: 20px;
}

details summary:focus {
  outline: none;
}

summary {
  width: 100%;
  /* border-bottom: 1px solid #e0eafc; */
  border-bottom: 1px solid #ffffff;
}

summary::-webkit-details-marker {
  display: none;
}
summary:not(:only-child):before {
  content: "\e791";
  color: #606266;
  transition: color 0.15s linear;
  font-size: 16px;
  cursor: pointer;
  margin-right: 6px;
  font-family: element-icons !important;
}
details[open] > summary:not(:only-child):before {
  content: "\e790";
  color: #606266;
  transition: color 0.15s linear;
  font-size: 16px;
  cursor: pointer;
  margin-right: 6px;
  font-family: element-icons !important;
}

.tree {
  /* background: linear-gradient(90deg, #8e9eab 0%, #eef2f3 100%); */
  margin-bottom: 30px;
}
/* Haruyuki row height line */
.tree-item {
  height: 40px;
  line-height: 40px;
  transition: all 1s ease 0s;
  user-select: none;
  -moz-user-select: none; /*火狐*/
  -webkit-user-select: none; /*webkit浏览器*/
  -ms-user-select: none; /*IE10*/
  -khtml-user-select: none; /*早期浏览器*/
}
.tree-item:hover {
  background: rgba(195,207,226, 0.2);
  border-radius: 6px;
}

.aisle-policy-bg {
  /* background-color: #e0eafc; */
  background-color: #f9fafc;
  /* padding: 6px 0; */
  padding-left: -10px;
  padding-right: 10px;
  border-radius: 6px;
  /* box-shadow: 0 2px 12px rgba(224, 234, 252, 0.8); */
  box-shadow: 0 2px 12px rgba(153,167,177, 0.4);
  color: #111111;
}

.summary-box {
  display: flex;
  align-items: center;
  padding: 6px 0;
}

.input-tree-item {
  display: flex;
  align-items: center;
}

.input-tree-item-left {
  width: 300px;
}

.policy-mr-3 {
  margin-right: 3px;
}
.policy-ml-3 {
  margin-left: 3px;
}
</style>
